package com.ruoyi.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.Bookinfo;
import com.ruoyi.book.service.IBookinfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书信息Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/book/bookinfo")
public class BookinfoController extends BaseController {
    @Autowired
    private IBookinfoService bookinfoService;

    /**
     * 查询图书信息列表
     */
    @PreAuthorize("@ss.hasPermi('book:bookinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bookinfo bookinfo) {
        startPage();
        List<Bookinfo> list = bookinfoService.selectBookinfoList(bookinfo);
        return getDataTable(list);
    }


    /**
     * 查询图书信息列表
     */
    @GetMapping("/listBookinfo")
    public TableDataInfo listBookinfo() {

        List<Bookinfo> bookinfos = bookinfoService.listBookinfo();
        return getDataTable(bookinfos);

    }




    /**
     * 导出图书信息列表
     */
    @PreAuthorize("@ss.hasPermi('book:bookinfo:export')")
    @Log(title = "图书信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bookinfo bookinfo) {
        List<Bookinfo> list = bookinfoService.selectBookinfoList(bookinfo);
        ExcelUtil<Bookinfo> util = new ExcelUtil<Bookinfo>(Bookinfo.class);
        util.exportExcel(response, list, "图书信息数据");
    }

    /**
     * 获取图书信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('book:bookinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bookinfoService.selectBookinfoById(id));
    }

    /**
     * 新增图书信息
     */
    @PreAuthorize("@ss.hasPermi('book:bookinfo:add')")
    @Log(title = "图书信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bookinfo bookinfo) {
        return toAjax(bookinfoService.insertBookinfo(bookinfo));
    }

    /**
     * 修改图书信息
     */
    @PreAuthorize("@ss.hasPermi('book:bookinfo:edit')")
    @Log(title = "图书信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bookinfo bookinfo) {
        return toAjax(bookinfoService.updateBookinfo(bookinfo));
    }

    /**
     * 删除图书信息
     */
    @PreAuthorize("@ss.hasPermi('book:bookinfo:remove')")
    @Log(title = "图书信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bookinfoService.deleteBookinfoByIds(ids));
    }
}
